﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="lekiPacjenta.aspx.cs" Inherits="STS.lekiPacjenta" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Label ID="id_pacjenta" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="tekst" runat="server" Text="Label" Visible="False"></asp:Label>
    <br />
    <br />
    <asp:Panel ID="Panel1" runat="server">
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MGRConnectionString %>" 
            DeleteCommand="DELETE FROM [pacjent_lek] WHERE [id_pacjent_lek] = @id_pacjent_lek" 
            InsertCommand="INSERT INTO [pacjent_lek] ([id_pacjenta], [id_leku], [pora], [ile]) VALUES (@id_pacjenta, @id_leku, @pora, @ile)" 
            SelectCommand="SELECT * FROM [pacjent_lek] WHERE ([id_pacjenta] = @id_pacjenta)" 
            UpdateCommand="UPDATE [pacjent_lek] SET [id_pacjenta] = @id_pacjenta, [id_leku] = @id_leku, [pora] = @pora, [ile] = @ile WHERE [id_pacjent_lek] = @id_pacjent_lek">
            <DeleteParameters>
                <asp:Parameter Name="id_pacjent_lek" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="id_pacjenta" Type="Int32" />
                <asp:Parameter Name="id_leku" Type="Int32" />
                <asp:Parameter Name="pora" Type="String" />
                <asp:Parameter Name="ile" Type="Int32" />
            </InsertParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="id_pacjenta" Name="id_pacjenta" 
                    PropertyName="Text" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="id_pacjenta" Type="Int32" />
                <asp:Parameter Name="id_leku" Type="Int32" />
                <asp:Parameter Name="pora" Type="String" />
                <asp:Parameter Name="ile" Type="Int32" />
                <asp:Parameter Name="id_pacjent_lek" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <br />
        <strong>Leki Pacjenta:<br /> </strong>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="id_pacjent_lek" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField CancelText="Anuluj" DeleteText="Usuń" EditText="Edytuj" 
                    ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="id_pacjent_lek" HeaderText="id_pacjent_lek" 
                    InsertVisible="False" ReadOnly="True" SortExpression="id_pacjent_lek" 
                    Visible="False" />
                <asp:BoundField DataField="id_pacjenta" HeaderText="id_pacjenta" 
                    SortExpression="id_pacjenta" Visible="False" />
                <asp:TemplateField HeaderText="id_leku" SortExpression="id_leku">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="nazwa" DataValueField="id_leku" 
                            SelectedValue='<%# Bind("id_leku") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownList3" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="nazwa" DataValueField="id_leku" 
                            SelectedValue='<%# Bind("id_leku") %>'>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="pora" HeaderText="pora" SortExpression="pora" />
                <asp:BoundField DataField="ile" HeaderText="ile" SortExpression="ile" />
            </Columns>
        </asp:GridView>
        <br />
        <strong>Nowy Lek:</strong><br />
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            DataKeyNames="id_pacjent_lek" DataSourceID="SqlDataSource1" 
            DefaultMode="Insert" Height="50px" Width="125px">
            <Fields>
                <asp:TemplateField HeaderText="id_leku" SortExpression="id_leku">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="nazwa" DataValueField="id_leku">
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="nazwa" DataValueField="id_leku" 
                            SelectedValue='<%# Bind("id_leku") %>'>
                        </asp:DropDownList>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="nazwa" DataValueField="id_leku">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="pora" HeaderText="pora" SortExpression="pora" />
                <asp:BoundField DataField="ile" HeaderText="ile" SortExpression="ile" />
                <asp:CommandField ButtonType="Button" ShowInsertButton="True" 
                    CancelText="Anuluj" InsertText="Dodaj" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MGRConnectionString %>" 
            SelectCommand="SELECT [nazwa], [id_leku] FROM [lek]"></asp:SqlDataSource>
    </asp:Panel>
    <br />
    <br />
    <br />
    <br />
    <br />
</asp:Content>
